// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

// Data type to represent a module import directive

#ifndef IMPORT_H
#define IMPORT_H

#include <string>

/**
 * An imported class or module.
 * May be attached to an ASTNode of type AST_IMPORT.
 */
class Import {
private:
	std::wstring m_importClsName;
	std::wstring m_alias;
	bool m_isStaticImport;

	Import(const Import &);
	Import& operator=(const Import &);

	Import(const std::wstring &importClsName, const std::wstring &alias, bool isStaticImport = false);
	~Import();

public:
	/**
	 * Create an Import for given class.
	 *
	 * @param importClsName the fully-qualified name of the imported class
	 */
	static Import *alloc(const std::wstring &importClsName);

	/**
	 * Create an Import for given class,
	 * using given name as an alias.
	 *
	 * @param importClsName the fully-qualified name of the imported class
	 * @param alias         alias by which the class will be referred to
	 */
	static Import *alloc(const std::wstring &importClsName, const std::wstring &alias);

	/**
	 * Create a static Import for given method in given module.
	 *
	 * @param importClsName the fully-qualified name of the imported class
	 * @param methodName    alias by which the class will be referred to
	 */
	static Import *allocStatic(const std::wstring &importModuleName, const std::wstring &methodName);

	/**
	 * Return whether or not this is a static import
	 * (of a method from a module.)
	 */
	bool isStatic() const { return m_isStaticImport; }

	/**
	 * Destroy an Import object.
	 *
	 * @param import the Import object to destroy
	 */
	static void destroy(Import *import);

	/**
	 * Get fully-qualified name of imported class.
	 */
	const std::wstring &getImportClsName() const;

	/**
	 * Get the alias by which the class will be referred to.
	 */
	const std::wstring &getAlias() const;
};

#endif /* IMPORT_H */
